package com.easybuilder.common.base.service.impl;

import com.easybuilder.common.base.dao.BaseDao;
import com.easybuilder.common.base.entity.BaseEntity;
import com.easybuilder.common.base.entity.DynamicEntity;
import com.easybuilder.common.base.service.BaseService;
import com.easybuilder.common.utils.DBUtil;
import com.easybuilder.common.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ZXS
 * @version 1.0
 * @description 类
 * @date 2021-5-27 21:22
 */
@Service
public class BaseServiceImpl implements BaseService {

    //统一保存
    @Override
    public BaseEntity doSave(BaseEntity entity) {
        String id = entity.getEntity().getString("id");
        if (StringUtil.isEmpty(id)) { //主键为空，insert
            long insertId = DBUtil.insert(entity);
            entity.getEntity().put("id", insertId);
        } else { //主键不为空，update
            DBUtil.update(entity);
        }
        return entity;
    }

    //批量删除
    @Override
    public long delete(BaseEntity baseEntity) {

        return DBUtil.delete(baseEntity);
    }
}
